package com.sxm.yiwei.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.sxm.yiwei.R;

import java.util.HashMap;
import java.util.List;

/**
 * Created by KuKa on 2017/6/19.
 * 取货列表
 */

public class PickupListAdapter extends BaseAdapter {
   private List<HashMap<String,String>> mList;
   private Context context;
    private Callback mCallback;

    public void setOnClick(Callback callback) {
        this.mCallback=callback;
    }




    public interface  Callback{
        void onclick(int v);
        void onclick1(int v);
    }



    public PickupListAdapter(Context context, List<HashMap<String,String>> mList) {
        this.context=context;
        this.mList=mList;
    }

    @Override
    public int getCount() {
        return mList.size()==0?0:mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        View view;
        ViewHolder holder;
        if (convertView==null){
            view= LayoutInflater.from(context).inflate(R.layout.book_pickupitem,null);
            holder = new ViewHolder();
            holder.address = (TextView) view.findViewById(R.id.pickup_contentaddress);
            holder.dispatch = (TextView) view.findViewById(R.id.pickup_contentdispatch);
            holder.explain = (TextView) view.findViewById(R.id.pickup_contentexplain);
            holder.price = (TextView) view.findViewById(R.id.pickup_contentprice);
            holder.sendtime = (TextView) view.findViewById(R.id.pickup_contentsendtime);
            holder.bt1 = (Button) view.findViewById(R.id.pickup_contentbt1);
            holder.bt2 = (Button) view.findViewById(R.id.pickup_contentbt2);
            view.setTag(holder);
        }else {
            view=convertView;
            holder = (ViewHolder) view.getTag();
        }
        /**
         *  map.put("consignorAddr","北京西路888号");
         map.put("id","12346");
         map.put("intro","电脑配件");
         map.put("orderCode","1234567890");
         map.put("totalAmount","100.00");
         map.put("publishTime","14.20");
         */
        holder.address.setText(mList.get(position).get("consignorAddr"));
        holder.sendtime.setText(mList.get(position).get("publishTime"));
        holder.price.setText(mList.get(position).get("totalAmount"));
        holder.explain.setText(mList.get(position).get("intro"));

        holder.bt1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mCallback!=null){
                    mCallback.onclick(position);
                }
            }
        });

        holder.bt2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mCallback!=null){
                    mCallback.onclick1(position);
                }
            }
        });


        return view;
    }
    class ViewHolder{
        private TextView sendtime,address,dispatch,explain,price;
        private Button bt1,bt2;

    }
}
